package com.link.base.base.contract.service;

import com.link.base.base.contract.dao.mybatis.mapper.ReceivePlanMapper;
import com.link.base.base.contract.model.ReceivePlan;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 开票回款计划
 *
 * @author 王昊
 * @date 2021-03-18 10:23:42
 */
@Service
public class ReceivePlanServiceImpl extends BasicServiceImpl<ReceivePlan> implements ReceivePlanService {

    @Resource
    private ReceivePlanMapper    receivePlanMapper;

    @Override
    public BasicMapper<ReceivePlan> getBasicMapper() {
        return receivePlanMapper;
    }

    /**
     * 插入数据前赋值开票阶段
     * @param entity
     * @throws Exception
     */
    @Override
    public void beforInsert(ReceivePlan entity) throws Exception {
        //查询模具回款计划ID查询当前回款计划所有计划行，size+1赋值给当前行开票阶段
        ReceivePlan querPlan = new ReceivePlan();
        querPlan.setModReceivableId(entity.getModReceivableId());
        List<ReceivePlan> receivePlans = receivePlanMapper.queryAll(querPlan);
        int size = receivePlans.size();
        size++;
        entity.setInvoiceStage(String.format("第%d次开票", size));
    }
}